﻿using Agile.Infra.Pay.WxPay.Models;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;

namespace Agile.Infra.Pay.WxPay
{
    public partial class WxPayService
    {
        public async Task<WxPayNotifyResponse> NotifyAsync(HttpRequest httpRequest, WxPayNotifyRequest request)
        {
            // 验证签名
            CheckNotifySign(httpRequest, request);

            // 解密回调报文
            var res = new WxPayNotifyResponse
            {

            };

            return await Task.FromResult(res);
        }

        internal class WxPayNotifyModel
        {
            /// <summary>微信分配的小程序ID</summary>
            [JsonProperty("appid")]
            public string AppID { get; set; }

            /// <summary>商家数据包，原样返回</summary>
            [JsonProperty("attach")]
            public string Attach { get; set; }

            /// <summary>银行类型，采用字符串类型的银行标识</summary>
            [JsonProperty("bank_type")]
            public string BankType { get; set; }

            /// <summary>现金支付金额订单现金支付金额</summary>
            [JsonProperty("cash_fee")]
            public long CashFee { get; set; }

            /// <summary>货币类型，符合ISO4217标准的三位字母代码，默认人民币：CNY</summary>
            [JsonProperty("fee_type")]
            public string FeeType { get; set; }

            /// <summary>用户是否关注公众账号</summary>
            [JsonProperty("is_subscribe")]
            public string IsSubscribe { get; set; }

            /// <summary>微信支付分配的商户号</summary>
            [JsonProperty("mch_id")]
            public string MchID { get; set; }

            /// <summary>随机字符串，不长于32位</summary>
            [JsonProperty("nonce_str")]
            public string NonceStr { get; set; }

            /// <summary>用户在商户appid下的唯一标识</summary>
            [JsonProperty("openid")]
            public string OpenID { get; set; }

            /// <summary>商户系统内部订单号，要求32个字符内（最少6个字符），只能是数字、大小写字母_-|*且在同一个商户号下唯一</summary>
            [JsonProperty("out_trade_no")]
            public string OutTradeNo { get; set; }

            /// <summary>SUCCESS/FAIL</summary>
            [JsonProperty("result_code")]
            public string ResultCode { get; set; }

            /// <summary>SUCCESS/FAIL，此字段为SUCCESS其它字段才有值</summary>
            [JsonProperty("return_code")]
            public string ReturnCode { get; set; }

            /// <summary>签名</summary>
            [JsonProperty("sign")]
            public string Sign { get; set; }

            /// <summary>支付完成时间，格式为yyyyMMddHHmmss，如2009年12月25日9点10分10秒表示为20091225091010。</summary>
            [JsonProperty("time_end")]
            public string TimeEnd { get; set; }

            /// <summary>订单总金额，单位为分。
            /// 单位为元的请用TotalAmount字段</summary>
            [JsonProperty("total_fee")]
            public long TotalFee { get; set; }

            /// <summary>JSAPI、NATIVE、APP</summary>
            [JsonProperty("trade_type")]
            public string TradeType { get; set; }

            /// <summary>微信支付订单号</summary>
            [JsonProperty("transaction_id")]
            public string TransactionID { get; set; }

            /// <summary>订单总金额，单位为元</summary>
            public decimal TotalAmount { get { return TotalFee / 0.01M; } }
        }
    }
}
